package cn.kgc.permanager01.service.impl;

import cn.kgc.permanager01.mapper.PersonMapper;
import cn.kgc.permanager01.pojo.Person;
import cn.kgc.permanager01.service.PersonService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 *
 */
@Service
public class PersonServiceImpl implements PersonService {
    @Resource
    PersonMapper personMapper;
    @Override
    public PageInfo<Person> select(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Person> takeoutList=personMapper.selectByExample(null);
        PageInfo<Person> pageInfo=new PageInfo<>(takeoutList);
        return pageInfo;
    }

    @Override
    public Integer add(Person person) {
        int i=personMapper.insert(person);
        return i;
    }

    @Override
    public Person selectById(Integer id) {
        Person person=personMapper.selectByPrimaryKey(id);
        return person;
    }

    @Override
    public Integer update(Person person) {
        int i=personMapper.updateByPrimaryKey(person);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=personMapper.deleteByPrimaryKey(id);
        return i;
    }
}
